package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.XbbAggregatedPage;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.CustomerCommunicateDeleteDTO;
import com.xbongbong.paas.pojo.dto.CustomerMergeDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.FormDataThoroughDeleteDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.FormDataAddGetVO;
import com.xbongbong.paas.pojo.vo.FormDataRepeatVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FocusDTO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessrule.pojo.dto.OperationDTO;
import com.xbongbong.pro.common.pojo.dto.CustomerCheckRepeatDTO;
import com.xbongbong.pro.common.pojo.dto.RepeatCommonConditionDTO;
import com.xbongbong.pro.customer.pojo.dto.ChangeStatusDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerCardDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerDeleteBatchDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerEditAttrUpdateDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerUpdateBatchDTO;
import com.xbongbong.pro.customer.pojo.vo.CustomerDeleteBatchVO;
import com.xbongbong.pro.customer.pojo.vo.CustomerEditAttrUpdateVO;
import com.xbongbong.pro.customer.pojo.vo.CustomerUpdateBatchVO;
import com.xbongbong.pro.domain.entity.SpecialUpdateCustomerDataEntity;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formexplain.pojo.vo.LinkFormItemVO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.saas.domain.entity.ext.CustomerEntityExt;

import java.util.List;
import java.util.Map;


/**
 * @author haibing.zhang
 * @version v1.0
 * @date 2019/1/18
 * @since v1.0
 */
public interface CustomerService {
    /**
     * 客户保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 客户保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 客户里关联新建联系人校验联系人
     *
     * @param corpid       公司id
     * @param contactArray 联系人数据
     * @param dataId       客户id
     * @param name         客户名称
     * @author feng.zheng
     * @date 2019/2/21 20:42
     */
    void verifyContact(String corpid, JSONArray contactArray, Long dataId, String name, ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 重点客户关注
     *
     * @param focusDTO 参数
     * @return BaseVO
     * @throws XbbException 业务异常
     */
    BaseVO focus(FocusDTO focusDTO) throws XbbException;

    /**
     * 根据客户id队列查找符合要求的客户列表
     * @param corpid 公司ID
     * @param customerIds 客户id列表
     * @throws XbbException 业务异常
     * @return
     */
    List<CustomerEntityExt> getCustomerListByIds(String corpid, List<Long> customerIds) throws XbbException;

    /**
     * 客户名称实时查重
     *
     * @param repeatCommonConditionDTO 查重共用条件
     * @param customerName             客户名称
     * @return com.xbongbong.paas.pojo.vo.FormDataRepeatVO
     * @author feng.zheng
     * @throws XbbException 业务异常
     * @date 2019/2/20 13:47
     */
    FormDataRepeatVO checkRepeatForCustomerName(RepeatCommonConditionDTO repeatCommonConditionDTO, String customerName) throws XbbException;

    /**
     * 更新
     * @author 吴峰
     * @date 15:42 2019/2/15
     * @desrcption
     * @param customerUpdateBatchDTO 客户名称更新入参
     * @return void
     * @throws XbbException 业务异常
     */
    CustomerUpdateBatchVO customerUpdateBatch(CustomerUpdateBatchDTO customerUpdateBatchDTO) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities 业务实体集合
     * @param totalCount 总数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-11 13:50
     */
    ListAppVO formatCustomerAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * 格式化移动端客户查重列表页
     *
     * @param customerCheckRepeatDTO 参数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-11 13:50
     */
    ListAppVO formatDuplicateCustomerAppList(CustomerCheckRepeatDTO customerCheckRepeatDTO) throws XbbException;

    /**
     * 批量删除客户
     * @author 吴峰
     * @date 2019/3/14 10:08
     * @param customerDeleteBatchDTO
     * @return com.xbongbong.pro.customer.pojo.vo.CustomerDeleteBatchVO
     * @throws XbbException 业务异常
     */
    CustomerDeleteBatchVO deleteBatch(CustomerDeleteBatchDTO customerDeleteBatchDTO) throws XbbException;

    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/18 19:15
     * @param customerEditAttrUpdateDTO
     * @return com.xbongbong.pro.customer.pojo.vo.CustomerEditAttrUpdateVO
     * @throws XbbException 业务异常
     */
    CustomerEditAttrUpdateVO batchEditAttr(CustomerEditAttrUpdateDTO customerEditAttrUpdateDTO) throws XbbException;

    /**
     * 更改客户状态
     *
     * @param changeStatusDTO
     * @throws
     * @author long.rao
     * @date 2019-04-15 20:41
     */
    BaseVO changeStatus(ChangeStatusDTO changeStatusDTO) throws XbbException;

    /**
     * 名片扫描数据缓存
     * @param customerCardDTO
     * @return
     */
    BaseVO customerCardSet(CustomerCardDTO customerCardDTO) throws XbbException;

    /**
     * 名片扫描新建页
     * @param baseDTO
     * @return
     */
    FormDataAddGetVO customerCardGet(BaseDTO baseDTO) throws XbbException;

    /**
     * 名片扫描新建联系人页
     * @param baseDTO
     * @return
     * @throws XbbException
     */
    LinkFormItemVO customerCardContactGet(BaseDTO baseDTO) throws XbbException;

    /**
     * 封装客户查重
     * @param customerCheckRepeatDTO
     * @return
     */
    XbbAggregatedPage<PaasFormDataEntityExt> getDuplicateCustomer(CustomerCheckRepeatDTO customerCheckRepeatDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO   导入入参
     * @param titlePojoList       标题
     * @param rowGroupPojo        一个表单对应的一组Excel填写的数据
     * @param fieldAttrList       解释
     * @param contactLabelAttr
     * @param contactLabelPojoMap
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList, String contactLabelAttr, Map<String, JSONObject> contactLabelPojoMap) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList, Integer businessType) throws XbbException;

    /**
     * 业务规则之修改某些字段数据
     * @param operationDTO
     * @throws XbbException
     */
    void updateBatchByBusinessRule(OperationDTO operationDTO) throws XbbException;

    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    String getCutomerNameStr(List<Long> lackCustomerIdList, String corpid) throws XbbException;

    void afterSaveForImport(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
    /**
     * 同步上级客户的名称
     *
     * @param corpid
     * @param dataId
     * @param name
     */
     void dataConsistencyUpdateParentCustomer(String corpid, Long dataId, String name);

    /**
     * 批量编辑修改标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    /**
     * 客户合并
     * @param formDataListDTO
     * @return
     * @throws XbbException
     */
    BaseVO customerMerge(CustomerMergeDTO formDataListDTO) throws XbbException;
    
    List<Long> deleteCustomerCommunicate(FormDataThoroughDeleteDTO formDataThoroughDeleteDTO, List<Long> allowDeleteCustomerId) throws XbbException;

    void dataConsistencyUpdateClue(String corpid, Long dataId, String companyName) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void updateBatch4Script(List<SpecialUpdateCustomerDataEntity> updateDataEntityList) throws XbbException;

    void customerCommunicateRemoveByScript(CustomerCommunicateDeleteDTO communicateDeleteDTO) throws XbbException;
}
